package com.authentications.utils;

import java.io.Serializable;

/**
 * @ClassName ResultBean
 * @Author xiezhuocai
 * @Description 通用返回元组
 * @Date 2021/12/16 8:45
 */
public class ResultBean<T> implements Serializable {
    private static final long serialVersionUID = -1549643581827130116L;
    private T data;
    private Integer code;
    private String msg;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static <T> ResultBean<T> succeed(T data){
        ResultBean result = new ResultBean();
        result.setCode(200);
        result.setMsg("OK");
        result.setData(data);
        return result;
    }

    public static <T> ResultBean<T> error(T data,Integer code,String message){
        ResultBean result = new ResultBean();
        result.setCode(code);
        result.setMsg(message);
        result.setData(data);
        return result;
    }

    public static <T> ResultBean<T> defaultError(T data){
        return error(data,501,"NO");
    }
}
